﻿using System;
using System.Collections.Generic;

// 形状接口
public interface IShape
{
    double CalculateArea(); // 计算面积方法
    string GetInfo(); // 获取形状信息方法
}

// 长方形类
public class Rectangle : IShape
{
    private double width;
    private double height;

    public Rectangle(double width, double height)
    {
        this.width = width;
        this.height = height;
    }

    public double CalculateArea()
    {
        return width * height;
    }

    public string GetInfo()
    {
        return "长方形：宽度 = " + width + "，高度 = " + height;
    }
}

// 正方形类
public class Square : IShape
{
    private double side;

    public Square(double side)
    {
        this.side = side;
    }

    public double CalculateArea()
    {
        return side * side;
    }

    public string GetInfo()
    {
        return "正方形：边长 = " + side;
    }
}

// 三角形类
public class Triangle : IShape
{
    private double baseLength;
    private double height;

    public Triangle(double baseLength, double height)
    {
        this.baseLength = baseLength;
        this.height = height;
    }

    public double CalculateArea()
    {
        return 0.5 * baseLength * height;
    }

    public string GetInfo()
    {
        return "三角形：底边长度 = " + baseLength + "，高度 = " + height;
    }
}

// 简单工厂类
public class ShapeFactory
{
    // 随机数生成器
    private static Random random = new Random();

    // 创建形状对象方法
    public static IShape CreateShape()
    {
        int shapeType = random.Next(3); // 生成随机数，决定创建哪种形状对象

        switch (shapeType)
        {
            case 0:
                return new Rectangle(random.Next(1, 10), random.Next(1, 10));
            case 1:
                return new Square(random.Next(1, 10));
            case 2:
                return new Triangle(random.Next(1, 10), random.Next(1, 10));
            default:
                throw new ArgumentException("无效的形状类型");
        }
    }
}

class Program
{
    static void Main(string[] args)
    {
        List<IShape> shapes = new List<IShape>();
        double totalArea = 0;

        // 创建10个随机形状对象
        for (int i = 0; i < 10; i++)
        {
            IShape shape = ShapeFactory.CreateShape();
            shapes.Add(shape);
            totalArea += shape.CalculateArea(); // 计算面积总和
        }

        // 展示生成的十个形状的信息
        Console.WriteLine("生成的形状:");
        foreach (IShape shape in shapes)
        {
            Console.WriteLine(shape.GetInfo());
        }

        // 输出总面积
        Console.WriteLine("总面积: " + totalArea);
    }
}
